#include "slepdef.h"
#include "slepblas.h"
#include "slep.h"
#include "sleputil.h"
#include <string.h>
#include "testblas1.h"
#include "slepmacros.h"

void testdaAxpy(){
	slep_matrix *A;
	slep_vector *x, *y;
	char filename[100];
	stopWatch timer;
	int i,j;

	
	for(i=1; i<=1000; i*=10)
		for(j=1000; j>=1; j/=10){
			A = slepAllocDenseMatrix(i,j);
			x = slepAllocDenseVector(j);
			y = slepAllocDenseVector(i);

			slep_randn(A->data.mtrx,i*j,0.,1.);
			slep_randn(x->data.vctr,j,0.,1.);

			startTimer(&timer);
			slep_daAxpby(SlepNoTranspose,1.,A,x,0.,y);
			stopTimer(&timer);
			printf("Time taken for multiplying A(%dx%d) = %lf\n", i,j,getElapsedTime(&timer));

			sprintf(filename,"A.%dx%d.mtrx",i,j);
			slepVerboseWriteDenseMatrix(filename,A);	
			sprintf(filename,"x.%dx%d.vctr",i,j);
			slepVerboseWriteDenseVector(filename,x);
			sprintf(filename,"y.%dx%d.vctr",i,j);
			slepVerboseWriteDenseVector(filename,y);
			slepFreeMatrix(A);
			slepFreeVector(x);
			slepFreeVector(y);

			A = slepAllocDenseMatrix(i,j);
			x = slepAllocDenseVector(i);
			y = slepAllocDenseVector(j);

			slep_randn(A->data.mtrx,i*j,0.,1.);
			slep_randn(x->data.vctr,i,0.,1.);

			startTimer(&timer);
			slep_daAxpby(SlepTranspose,1.,A,x,0.,y);
			stopTimer(&timer);
			printf("Time taken for multiplying A(%dx%dT) = %lf\n",i,j, getElapsedTime(&timer));

			sprintf(filename,"A.%dx%dT.mtrx",i,j);
			slepVerboseWriteDenseMatrix(filename,A);	
			sprintf(filename,"x.%dx%dT.vctr",i,j);
			slepVerboseWriteDenseVector(filename,x);
			sprintf(filename,"y.%dx%dT.vctr",i,j);
			slepVerboseWriteDenseVector(filename,y);
			slepFreeMatrix(A);
			slepFreeVector(x);
			slepFreeVector(y);

		}
}




void TestMEMMacros(){
	slep_vector *vector1 , *vector2, *vector3;
	int i;
	stopWatch timer;

	vector1 = slepAllocDenseVector(100000);
	vector2 = slepAllocDenseVector(100000);
	vector3 = slepAllocDenseVector(100000);

	startTimer(&timer);
	memset(vector1->data.vctr,0,sizeof(double)* (vector1->dim) );
	stopTimer(&timer);

	printf("Time taken for setting zeroes(memset) = %lf\n", getElapsedTime(&timer));

	startTimer(&timer);
	DMEMSET(vector1->data.vctr, 0, vector1->dim, i);
	stopTimer(&timer);

	printf("Time taken for setting zeroes(DMEMSET) = %lf\n", getElapsedTime(&timer));

	startTimer(&timer);
	DMEMCPY(vector2->data.vctr, vector1->data.vctr, vector1->dim,i);
	stopTimer(&timer);

	printf("Time taken for setting zeroes(DMEMCPY) = %lf\n", getElapsedTime(&timer));

	startTimer(&timer);
	memcpy(vector3->data.vctr, vector1->data.vctr,vector1->dim * sizeof(double));
	stopTimer(&timer);

	printf("Time taken for setting zeroes(memcpy) = %lf\n", getElapsedTime(&timer));

	slepFreeVector(vector1);
	slepFreeVector(vector2);
	slepFreeVector(vector3);
	
}


void TestSlep_daxpby(){
	slep_vector* x, *y;
	int i;
	x = slepAllocDenseVector(10);
	y = slepAllocDenseVector(10);

	DMEMSET(x->data.vctr,1.0,10,i);
	DMEMSET(y->data.vctr,-2.0,10,i);

	printf("Before Multiplication\n");
	slepVerbConsoleWrDVec(x);
	slepVerbConsoleWrDVec(y);

	slep_dscal(2.0,y);
	slep_daxpy(3.0,x,y);

	/*
		^
		|
		v
	*/

	slep_daxpby(3.0,x,2.0,y);

	printf("After Multiplication\n");
	slepVerbConsoleWrDVec(x);
	slepVerbConsoleWrDVec(y);

}